package org.kernely.web;

import org.kernely.web.context.KernelyContextService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

/**
 * Bundle's activator
 */
public class Activator implements BundleActivator {

	// the serviceRegistration
	private ServiceRegistration contextServiceRegistration;

	/**
	 * Called when the bundle is STARTING
	 */
	public final void start(BundleContext pBundleContext) throws Exception {
		contextServiceRegistration = pBundleContext.registerService(ContextServiceInterface.class.getName(), new KernelyContextService(pBundleContext.getBundle()), null);
	}

	/**
	 * Called when the Bundle is STOPPING
	 */
	public final void stop(BundleContext context) throws Exception {
		if (contextServiceRegistration != null) {
			contextServiceRegistration.unregister();
			contextServiceRegistration = null;
		}
	}
}
